package com.iias.communication.message.client;


import com.iias.common.util.log.LogUtils;
import com.iias.communication.business.BusinessActuator;
import com.iias.communication.packet.ProPacket;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;

/**
 * 客户端 信息接收
 */
public class ClientHandler extends SimpleChannelInboundHandler<ProPacket> {
    private final static Logger log = LogUtils.getLogger();

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ProPacket proPacket) throws Exception {
        BusinessActuator.actuator(ctx.channel(),proPacket);
        log.info("server receive message :" + proPacket.getHeard().getMsgId());
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.channel().alloc().buffer();
        log.info("server receive message : ");
//        super.channelActive(ctx);
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause){
        log.warn("Unexpected exception from downstream.", cause);
        cause.printStackTrace();
        ctx.close();
    }
}